package com.aabbc.swagger.controller;


import com.aabbc.swagger.entity.UserInfo;
import com.aabbc.swagger.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhai
 * @since 2019-11-25
 */
@RestController
@RequestMapping("/userInfo")
@Api(value = "用户相关操作", tags = "用户相关操作")
public class UserInfoController {

    @Autowired
    IUserInfoService userInfoService;

    @ApiOperation("创建、修改用户")
    @PostMapping
    public Boolean create(@RequestBody UserInfo userInfo) {
        return userInfoService.saveOrUpdate(userInfo);
    }

    @ApiOperation("修改用户")
    @PutMapping
    public Boolean put(@RequestBody UserInfo userInfo) {
        return userInfoService.updateById(userInfo);
    }

    @ApiOperation("获取所有用户")
    @GetMapping
    public List<UserInfo> findAll() {
        return userInfoService.list();
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping(value = "/{id}")
    public Boolean deleteById(@PathVariable("id") Long id) {
        return userInfoService.removeById(id);
    }
}

